package com.xqboss.apps.mapper.consumer;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xqboss.apps.domain.consumer.ConsumerTeamMember;
import com.xqboss.apps.dto.consumer.ConsumerTeamDto;
import com.xqboss.apps.vo.consumer.ConsumerTeamMemberFamilyVo;
import com.xqboss.apps.vo.consumer.ConsumerTeamMemberReminderVo;
import com.xqboss.apps.vo.consumer.ConsumerTeamMemberVo;
import com.xqboss.apps.vo.consumer.ConsumerTeamVo;
import com.xqboss.apps.vo.team.WebConsumerTeamMemberFamilyVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;


/**
 * 队伍成员Mapper接口
 *
 * @author xqboss
 * @date 2023-08-15
 */
public interface ConsumerTeamMemberMapper extends BaseMapper<ConsumerTeamMember> {
    /**
     * 查询队伍成员
     *
     * @param id 队伍成员主键
     * @return 队伍成员
     */
    public ConsumerTeamMember selectConsumerTeamMemberById(Long id);

    /**
     * 查询队伍成员列表
     *
     * @param consumerTeamMember 队伍成员
     * @return 队伍成员集合
     */
    public List<ConsumerTeamMember> selectConsumerTeamMemberList(ConsumerTeamMember consumerTeamMember);

    /**
     * 新增队伍成员
     *
     * @param consumerTeamMember 队伍成员
     * @return 结果
     */
    public int insertConsumerTeamMember(ConsumerTeamMember consumerTeamMember);

    /**
     * 修改队伍成员
     *
     * @param consumerTeamMember 队伍成员
     * @return 结果
     */
    public int updateConsumerTeamMember(ConsumerTeamMember consumerTeamMember);

    /**
     * 删除队伍成员
     *
     * @param id 队伍成员主键
     * @return 结果
     */
    public int deleteConsumerTeamMemberById(Long id);

    /**
     * 批量删除队伍成员
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteConsumerTeamMemberByIds(Long[] ids);

    List<ConsumerTeamVo> topList(@Param("list") List<Long> ids,@Param("teamId") Integer teamId);

    int deleteConsumerTeamMember(@Param("id") Integer id, @Param("memberIds") List<Long> teamMemberIds);

    int updateConsumerTeamMemberByTeamId(ConsumerTeamMember teamMember);

    Long getId(@Param("teamId") Integer teamId, @Param("userId") Long userId);

    /**
     * 队伍当日参与打卡人数量
     * @param teamId
     * @return
     */
    List<Long> teamPunchMemberCount(Integer teamId);

    /**
     * 统计当前队伍里面的成员已实名的成员个数
     *
     * @param teamId 队伍id
     * @return 已实名的成员个数
     */
    @Select("SELECT\n" +
            "\tCOUNT(*) \n" +
            "FROM\n" +
            "\tconsumer_real_name s \n" +
            "WHERE\n" +
            "\ts.auth_status = 1 \n" +
            "\tAND s.user_id IN ( SELECT c.user_id FROM consumer_team_member c WHERE c.team_id = #{teamId} AND c.del_flag = 0 ) \n" +
            "\tAND s.del_flag =0")
    int countTeamRealName(@Param("teamId") long teamId) ;

    /**
     * 获取指定队伍主成员的家庭成员基本信息
     *
     * @param teamId 队伍id
     * @param userId 主成员id
     * @return 家庭成员基本信息
     */
    List<ConsumerTeamMemberVo> selectBasicInfos(@Param("teamId") Integer teamId,
                                                @Param("parentId") Long userId);

    /**
     * 获取要解除家庭亲属关系的家庭成员基本信息
     *
     * @param teamId 队伍id
     * @param userId 主成员id
     * @param secureUserId 需要解除亲属关系的亲属用户id
     * @return  要解除家庭亲属关系的家庭成员基本信息
     */
    ConsumerTeamMemberVo selectBasicInfo(@Param("teamId") Integer teamId,
                                         @Param("parentId") Long userId,
                                         @Param("userId") Long secureUserId);

    /**
     * 查询指定队伍家庭所有成员(包括当日解除家庭关系的成员，以及退出队伍的队长或主成员)
     *
     * @param teamId 队伍id
     * @param date 当日
     * @return 家庭信息
     */
    List<ConsumerTeamMemberFamilyVo> selectTeamMembers(@Param("teamId") Integer teamId,@Param("date") LocalDate date);

    List<WebConsumerTeamMemberFamilyVo> infoMembers(ConsumerTeamDto params);

    /**
     *
     * 获取提醒打卡人的基本信息
     *
     * @param teamId 队伍id
     * @param reminderUserId 提醒方用户id
     * @param toReminderUserId 被提醒方用户id
     * @return ConsumerTeamMemberReminderVo
     */
    ConsumerTeamMemberReminderVo teamMemberReminderInfo(@Param("teamId")Long teamId,
                                                        @Param("reminderUserId")Long reminderUserId,
                                                        @Param("toReminderUserId")Long toReminderUserId);
}
